
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>mysql和sequelizejs · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="nginx.html" />
    
    
    <link rel="prev" href="ping-mu.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    热度后台交接文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../wen-dang-lian-jie.html">
            
                <a href="../wen-dang-lian-jie.html">
            
                    
                    文档链接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    技术栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../hou-tai-dai-ma.html">
            
                <a href="../hou-tai-dai-ma.html">
            
                    
                    后台代码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="hou-tai-dai-ma-jie-gou-jie-shao.html">
            
                <a href="hou-tai-dai-ma-jie-gou-jie-shao.html">
            
                    
                    后台代码结构介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.html">
            
                <a href="fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.html">
            
                    
                    服务器登陆及代码拉取更新
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="ping-mu.html">
            
                <a href="ping-mu.html">
            
                    
                    pm2
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.4" data-path="mysql.html">
            
                <a href="mysql.html">
            
                    
                    mysql和sequelizejs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="nginx.html">
            
                <a href="nginx.html">
            
                    
                    nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="apidocs.html">
            
                <a href="apidocs.html">
            
                    
                    apidocs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../lian-xi-wo.html">
            
                <a href="../lian-xi-wo.html">
            
                    
                    更多问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >mysql和sequelizejs</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p><strong>mysql&#x548C;sequelizejs</strong></p>
<p>&#x9879;&#x76EE;&#x6570;&#x636E;&#x5E93;&#x7528;&#x7684;&#x662F;mysql&#xFF0C;sequelizejs&#x662F;&#x5BF9;&#x9879;&#x76EE;&#x548C;mysql&#x8FDE;&#x63A5;&#x8FDB;&#x884C;&#x4E86;&#x4E00;&#x5C42;&#x5C01;&#x88C5;</p>
<p>sequelizejs&#x6587;&#x6863; <a href="http://docs.sequelizejs.com/manual/tutorial/querying.html" target="_blank">http://docs.sequelizejs.com/manual/tutorial/querying.html</a></p>
<p>mysql&#x7B80;&#x5355;&#x6559;&#x7A0B; <a href="http://www.runoob.com/mysql/mysql-tutorial.html" target="_blank">https://www.mysql.com/</a></p>
<p>&#x6570;&#x636E;&#x5E93;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5728;server/config &#x76EE;&#x5F55;&#x4E0B;&#x9762;</p>
<p>&#x8BE5;&#x76EE;&#x5F55;&#x4E0B;&#x9762;&#x7684;&#x6587;&#x4EF6;&#x914D;&#x7F6E;&#x4E86;&#x670D;&#x52A1;&#x5668;&#x76D1;&#x542C;&#x7684;&#x7AEF;&#x53E3;,&#x6B63;&#x5F0F;&#x670D;&#x670D;&#x52A1;&#x5668;&#x548C;&#x672C;&#x673A;&#x6D4B;&#x8BD5;&#x670D;&#x52A1;&#x5668;&#x8FDE;&#x63A5;&#x7684;&#x6570;&#x636E;&#x5E93;&#x7684; ip &#x7AEF;&#x53E3; &#x7528;&#x6237;&#x540D; &#x5BC6;&#x7801; &#x6570;&#x636E;&#x5E93;&#x540D;</p>
<p><img src="../assets/mysql.png" alt=""></p>
<p>&#x6570;&#x636E;&#x5E93;&#x7684;&#x5C01;&#x88C5;&#x548C;sequelizejs&#x7684;&#x521D;&#x59CB;&#x5316;&#x5DF2;&#x7ECF;&#x6570;&#x636E;&#x5E93;&#x8868;&#x7684;&#x521B;&#x5EFA;&#x4F7F;&#x7528;&#x5728;server/src/models/ &#x4E0B;&#x9762;</p>
<p>&#x5176;&#x4E2D; db/sequelize.js &#x5BFC;&#x5165;&#x4E86;sequelizejs&#x5E76;&#x8BBE;&#x7F6E;&#x4E00;&#x4E0B;&#x6570;&#x636E;&#x5E93;&#x7684;&#x57FA;&#x672C;&#x53C2;&#x6570;&#x5E76;&#x4ECE;config&#x91CC;&#x9762;&#x8BFB;&#x53D6;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4E00;&#x4E9B;&#x914D;&#x7F6E;&#x7136;&#x540E;&#x5728;index.js&#x91CC;&#x9762;&#x5BFC;&#x51FA;<img src="../assets/mysql_config.png" alt="">models &#x4E0B;&#x9762;&#x7684;index.js&#x8D1F;&#x8D23;&#x5BFC;&#x5165;&#x540C;&#x7EA7;&#x76EE;&#x5F55;&#x91CC;&#x9762;&#x5176;&#x4ED6;&#x7684;js&#x6587;&#x4EF6;(&#x8FD9;&#x4E9B;js&#x6587;&#x4EF6;&#x8D1F;&#x8D23;&#x5B9A;&#x4E49;&#x6570;&#x636E;&#x5E93;&#x7684;&#x8868;&#x7C7B;&#x578B;)&#x5E76;&#x4E00;&#x8D77;&#x5BFC;&#x51FA;</p>
<p><img src="../assets/mysql2.png" alt="">&#x5B9A;&#x4E49;&#x6570;&#x636E;&#x5E93;&#x8868;&#x548C;&#x6570;&#x636E;&#x5E93;&#x65B9;&#x6CD5;(&#x4EE5;work_normal.js&#x4E3E;&#x4F8B;)</p>
<p>&#x5F15;&#x5165;sequelize.js--&gt; &#x5B9A;&#x4E49;&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;--&gt;[&#x5B9A;&#x4E49;&#x6570;&#x636E;&#x5E93;&#x7279;&#x6709;&#x65B9;&#x6CD5;]--&gt;[&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;]--&gt;&#x5BFC;&#x51FA;&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;<img src="../assets/myql3.png" alt="">&#x5B9A;&#x4E49;&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;</p>
<p>&#x4E3B;&#x8981;&#x662F;&#x5B9A;&#x4E49;&#x6570;&#x636E;&#x5E93;&#x8868;&#x540D;&#x6DFB;&#x52A0;s&#x8868;&#x793A;&#x590D;&#xFF0C; &#x5B9A;&#x4E49;&#x5B57;&#x6BB5;&#x540D;&#x79F0; &#x7C7B;&#x578B; &#x7EA6;&#x675F; &#x9ED8;&#x8BA4;&#x503C;&#x7B49;&#xFF0C;&#x5B9A;&#x4E49;&#x5B57;&#x7B26;&#x7F16;&#x7801;&#xFF0C;&#x5176;&#x4ED6;&#x66F4;&#x591A;&#x8BBE;&#x7F6E;&#x53EF;&#x5728;&#x5B98;&#x65B9;&#x6587;&#x6863;&#x67E5;&#x627E;&#x66F4;&#x591A;<img src="../assets/mysql4.png" alt="">&#x5B9A;&#x4E49;&#x8BE5;&#x6570;&#x636E;&#x5BF9;&#x8C61;&#x7684;&#x7279;&#x6709;&#x65B9;&#x6CD5;(&#x89E3;&#x51B3;&#x4E86;sequelize&#x6CA1;&#x6709;&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E9B;&#x590D;&#x6742;&#x6570;&#x636E;&#x67E5;&#x8BE2;&#x64CD;&#x4F5C;)</p>
<p>&#x5BFC;&#x5165;sequelizejs &#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x67E5;&#x8BE2;&#x7ED3;&#x679C;<img src="../assets/mysql5.png" alt="">&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#x8868;</p>
<p>&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;&#x7684;sync&#x65B9;&#x6CD5;froce&#x4F20;true&#x5219;&#x6BCF;&#x6B21;&#x90FD;&#x4F1A;&#x5220;&#x9664;&#x4EE5;&#x524D;&#x6570;&#x636E;&#x5E76;&#x91CD;&#x65B0;&#x521B;&#x5EFA;&#x4E00;&#x5F20;&#x8868;&#xFF0C;false&#x5219;&#x6CA1;&#x6709;&#x8BE5;&#x8868;&#x65F6;&#x4F1A;&#x521B;&#x5EFA;&#x8868;&#x6709;&#x5219;&#x4E0D;&#x521B;&#x5EFA;&#xFF0C;then&#x91CC;&#x9762;&#x662F;&#x6267;&#x884C;&#x5B8C;&#x521B;&#x5EFA;&#x6216;&#x4E0D;&#x521B;&#x5EFA;&#x64CD;&#x4F5C;&#x540E;&#x7684;&#x56DE;&#x8C03;<img src="../assets/mysql6.png" alt=""></p>
<p>sequelize&#x7684;&#x4E00;&#x4E9B;&#x57FA;&#x672C;&#x64CD;&#x4F5C;(&#x5047;&#x8BBE;A&#x4E3A;&#x6570;&#x636E;&#x5E93;&#x6A21;&#x578B;&#x5BF9;&#x8C61;)</p>
<p>&#x521B;&#x5EFA;&#x6570;&#x636E; A.create(&#x6570;&#x636E;&#x5BF9;&#x8C61;)</p>
<p>&#x67E5;&#x627E;&#x4E00;&#x4E2A; A.findOne() &#x6216;&#x8005; A.findOne({where:&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;}) order&#x6839;&#x636E;&#x4EC0;&#x4E48;&#x6392;&#x5E8F; limit&#x67E5;&#x770B;&#x591A;&#x5C11;&#x6761; $not&#x4E0D;&#x662F;&#x8FD9;&#x4E2A;&#x503C; $gt     $lt &#x5927;&#x4E8E;&#x5C0F;&#x4E8E;</p>
<p>&#x67E5;&#x627E;&#x6240;&#x6709; A.findAll() &#x6216;&#x8005; A.findAll({where:&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;})</p>
<p>&#x67E5;&#x8BE2;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;A.count() &#x6216;&#x8005; A.count({where:&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;})</p>
<p>&#x4FEE;&#x6539; &#x5148;&#x901A;&#x8FC7;find &#x6216;&#x8005; findOne &#x6216;findAll&#x65B9;&#x6CD5; &#x83B7;&#x53D6;&#x5BF9;&#x5E94;&#x5BF9;&#x8C61; &#x7136;&#x540E;&#x4FEE;&#x6539;&#x5BF9;&#x8C61;&#x5C5E;&#x6027; &#x5BF9;&#x8C61;.save()&#x4FDD;&#x5B58; &#x66F4;&#x591A;&#x5185;&#x5BB9;&#x67E5;&#x770B;&#x5B98;&#x65B9;&#x6587;&#x6863;</p>
<p>&#x6CE8;&#x610F;&#x4EE5;&#x4E0A;&#x65B9;&#x6CD5;&#x5168;&#x662F;&#x5F02;&#x6B65;&#x8C03;&#x7528; &#x6CE8;&#x610F;&#x4F7F;&#x7528;await&#x5173;&#x952E;&#x5B57; </p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="ping-mu.html" class="navigation navigation-prev " aria-label="Previous page: pm2">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="nginx.html" class="navigation navigation-next " aria-label="Next page: nginx">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"mysql和sequelizejs","level":"1.4.4","depth":2,"next":{"title":"nginx","level":"1.4.5","depth":2,"path":"hou-tai-dai-ma/nginx.md","ref":"hou-tai-dai-ma/nginx.md","articles":[]},"previous":{"title":"pm2","level":"1.4.3","depth":2,"path":"hou-tai-dai-ma/ping-mu.md","ref":"hou-tai-dai-ma/ping-mu.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"hou-tai-dai-ma/mysql.md","mtime":"2018-03-19T10:54:57.216Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-03-19T11:14:27.115Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

